from django.db import models
from django.contrib.auth.models import User as AdminUser


class BaseModel(models.Model):
    """为模型类补充字段"""
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_time = models.DateTimeField(verbose_name='更新时间', auto_now=True)

    class Meta:
        # 说明是抽象模型类
        abstract = True


class User(BaseModel):
    username = models.CharField(max_length=30)
    email = models.EmailField(max_length=50)
    password = models.CharField(max_length=30)
    admin_user = models.OneToOneField(AdminUser, on_delete=models.SET_NULL, null=True, blank=True)  # 一对一绑定用户

    def __str__(self):
        return self.username

    class Meta:
        ordering = ['-create_time']
